/**
 * 
 */
package com.edocbase.desktop.plugins.mdiary.actions;

import java.beans.PropertyChangeEvent;
import java.io.UnsupportedEncodingException;

import jnacontrib.win32.Registry;

import com.edocbase.desktop.maildriver.DesktopApplication;


/**
 * @author X61
 * 
 */
public class AutoRunAction extends AbstractAction implements IPropertyAction {

	public AutoRunAction() {
		super(Actions.Action.AUTO_RUN_ACTION.name());
	}

	@Override
	public void run(PropertyChangeEvent event) {
		String path = DesktopApplication.getPlatform().getExeFullPath();
		if (path.length()<1){
			return;
		}
		//Object obj = event.getNewValue();
		//boolean autoRun = (Boolean) obj;
		boolean autoRun =true;
		if (autoRun) {
			path = path.concat(" ").concat("tray");
			try {
				Registry.setStringValue(
						Registry.REGISTRY_ROOT_KEY.LOCAL_MACHINE,
						"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run",
						"desktopman", path);
			} catch (UnsupportedEncodingException e) {
				e.printStackTrace(System.err);
			}
		} else {
			Registry.deleteValue(Registry.REGISTRY_ROOT_KEY.LOCAL_MACHINE,
					"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run",
					"desktopman");
		}
	}

}
